package com.study.leetcode;

import java.util.HashMap;
import java.util.Map;

//https://leetcode.cn/problems/isomorphic-strings/
public class Solution_205 {
    public boolean isIsomorphic(String s, String t) {
        int len = s.length();
        Map<Character, Character> mp1 = new HashMap<>();
        Map<Character, Character> mp2 = new HashMap<>();
        for (int i = 0; i < len; i++) {
            char c1 = s.charAt(i);
            char c2 = t.charAt(i);
            Character m1 = mp1.get(c1);
            Character m2 = mp2.get(c2);
            if (m1 == null) {
                mp1.put(c1, c2);
            } else if (m1 != c2) {
                return false;
            }
            if (m2 == null) {
                mp2.put(c2, c1);
            } else if (m2 != c1) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Solution_205 solution205 = new Solution_205();
        boolean isomorphic = solution205.isIsomorphic("aacd", "bbcc");
        System.out.println("isomorphic = " + isomorphic);

    }
}
